﻿Imports System.Data.SqlClient
Public Class Vanneth_customer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddnewcust.Click

        Dim frm As New ADDNEW()
        If frm.ShowDialog() = Windows.Forms.DialogResult.OK Then
            DataGridView1.Rows.Clear()

            Dim cn As New SqlConnection
            cn.ConnectionString = "Server =DELL-PC\SQLEXPRESS; Database = SaleManagement; UID = sa; PWD = 123"
            cn.Open()

            Dim cmd As New SqlCommand()
            cmd.Connection = cn
            cmd.CommandText = "SELECT * FROM Customer WHERE CustomerName LIKE N'%" & txtsearch.Text & "%' OR Phone LIKE N'%" & txtsearch.Text & "%'"
            Dim reader As SqlDataReader = cmd.ExecuteReader()
            While reader.Read
                DataGridView1.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3))
            End While
            reader.Close()
        End If

    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub


    Private Sub customer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        Dim cn As New SqlConnection()
        cn.ConnectionString = "Server =DELL-PC\SQLEXPRESS; Database = SaleManagement; UID = sa; PWD = 123"
        cn.Open()

        Dim cmd As New SqlCommand()
        cmd.Connection = cn
        cmd.CommandText = "SELECT * From Customer;"
        Dim reader As SqlDataReader = cmd.ExecuteReader()
        While reader.Read()
            DataGridView1.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3))

        End While
        reader.Close()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub txtsearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.TextChanged
        DataGridView1.Rows.Clear()

        Dim cn As New SqlConnection
        cn.ConnectionString = "Server =DELL-PC\SQLEXPRESS; Database = SaleManagement; UID = sa; PWD = 123"
        cn.Open()

        Dim cmd As New SqlCommand()
        cmd.Connection = cn
        cmd.CommandText = "SELECT * FROM Customer WHERE CustomerName LIKE N'%" & txtsearch.Text & "%' OR Phone LIKE N'%" & txtsearch.Text & "%'"
        Dim reader As SqlDataReader = cmd.ExecuteReader()
        While reader.Read
            DataGridView1.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3))
        End While
        reader.Close()
    End Sub
End Class
